package com.gxa.eshops.admin.filters;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.eshps.cores.common.JsonResult;
import org.apache.shiro.web.filter.authc.UserFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

/**
 * @program: IntelliJ IDEA
 * @description:
 * @author: Mr.Wang
 * @create: 2022-06-29 11:14
 **/
public class LoginFilter extends UserFilter {

    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
        //登录失败时返回信息
        response.setContentType("application/json;charset=utf8");
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("50002");
        jsonResult.setMsg("请先登录");
        ObjectMapper objectMapper = new ObjectMapper();
        response.getWriter().write(objectMapper.writeValueAsString(jsonResult.getMap()));
    }
}
